package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

@Api(tags = "套餐相关接口")
@Slf4j
@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result page(SetmealPageQueryDTO dto){
        log.info("接到参数：{}",dto.toString());
        PageResult pr = setmealService.page(dto);
        return Result.success(pr);
    }
    @CacheEvict(cacheNames = "setmeal",key = "#dto.categoryId")
    @ApiOperation("新增套餐")
    @PostMapping
    public Result add(@RequestBody SetmealDTO dto){
        setmealService.add(dto);
        return Result.success();
    }
    @CacheEvict(cacheNames = "setmeal",allEntries = true)
    @ApiOperation("删除套餐")
    @DeleteMapping
    public  Result deleteBatch(Integer[] ids){
        setmealService.deleteBatch(ids);
        return Result.success();
    }
    @CacheEvict(cacheNames = "setmeal",allEntries = true)
    @ApiOperation("修改售卖状态")
    @PostMapping("/status/{status}")
    public  Result updateStatus(@PathVariable Integer status,Long id){
        setmealService.updateStatus(status,id);
        return  Result.success();
    }

    @ApiOperation("根据id查询套餐")
    @GetMapping("/{id}")
    public  Result selectById(@PathVariable Long id){
        SetmealVO sv = setmealService.selectById(id);
        return Result.success(sv);
    }

    @CacheEvict(cacheNames = "setmeal",allEntries = true)
    @ApiOperation("修改套餐")
    @PutMapping
    public Result update(@RequestBody SetmealDTO dto){
        setmealService.update(dto);
        return Result.success();
    }
}
